<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/include.inc.jsp" %>
<!DOCTYPE html>
<html>
<head>
    <%@include file="/WEB-INF/views/layout/base.ref.jsp" %>
    <link rel="stylesheet" href="${ctx}/static/meeting/controls/subGrid/subgrid.css"/>
</head>
<body>
<form method="post" id="form1" action="${ctx}/customsearch/select">
    <input type="hidden" name="arg" id="ids" value="${vo.arg}"/> <input type="hidden" name="code" id="code"
                                                                        value="${vo.code}"/> <input type="hidden"
                                                                                                    name="pageNum"
                                                                                                    value="${vo.pageNum}"/>
    <c:if test="${defaultParam != null }">
        <input type="hidden" name="defaultParam" value="${defaultParam}"/>
    </c:if>
    <div class="col-xs-12" style="position: fixed; top: 10px;">
        <div class="mtrow">
            <div class="mtcolall">
                <a class="mtbtn two" style="cursor: pointer;float: left;margin-right:20px;"
                   onclick="select_submit();return false;">确定</a>
                <c:forEach items="${listControl}" var="con">
                    <label class="mtlabel-auto">${con.controlName}：</label>
                    <c:choose>
                        <c:when test="${con.controlType == 0}">
                            <input type="text" class="mtinput" name="${con.fieldControl}"
                                   value="${vo[con.fieldControl]}"/>
                        </c:when>
                        <c:when test="${con.controlType == 1}">
                            <input type="text" class="mtinput" name="${con.fieldControl}"
                                   value="${vo[con.fieldControl]}"/>
                        </c:when>

                    </c:choose>
                </c:forEach>
                <a class="mtbtn search marginleft" href="#" onclick="submit_onclick()"><i
                        class="mtfa mt-search"></i><span>查询</span></a>
            </div>
        </div>
        <div>
            <table id="grid" style="margin-top: 10px;">
            </table>
        </div>
    </div>
    <input type="hidden" name="resultcallback" id="resultcallback" value="${resultcallback}">
</form>
</body>
</html>
<script src="${ctx}/static/meeting/controls/subGrid/jquery.subgrid.js" type="text/javascript"></script>
<script type="text/javascript">
    //子表控件对象
    var SubGrid;

    var option = {
        idField: "id",
        data: "",
        columns: ""
    }

    function submit_onclick() {
        $("#form1").submit();
    }

    window.onload = function () {
        option.columns = ${columns};
        option.data = ${data};
        SubGrid = $("#grid").subgrid(option).data("subgrid");
        if ($("#ids").val().length > 2) {
            $('.subgrid_row').each(function (index, row) {
                var row = $(this);
                row.find('[field]').each(function (i, input) {
                    var len = $("#ids").val().indexOf("," + this.value + ",")
                    if (len > -1) {
                        row.find("input[type='checkbox']").prop('checked', 'true');
                    }
                });

            });
        }
    }

    function select_submit() {
        var data = SubGrid.getSelectedRows();
        var result = [{
            "result1": ""
        }, {
            "result2": ""
        }, {
            "result2": ""
        }, {
            "result4": ""
        }, {
            "result5": ""
        }, {
            "result6": ""
        }, {
            "result7": ""
        }, {
            "result8": ""
        }, {
            "result9": ""
        }, {
            "result10": ""
        }];
        var hed = ["result1", "result2", "result3", "result4", "result5", "result6", "result7", "result8", "result9", "result10"];
        if (data.length == 0) {
            layer.msg("请选择数据", {
                icon: 3
            });
        } else {
            $.each(data, function (index, rowData) {
                $.each(hed, function (index, item) {
                    if (typeof (result[item]) != "undefined") {
                        result[item] = result[item] + "," + rowData[item];
                    } else {
                        result[item] = rowData[item];
                    }
                });
            });

            window.parent.sysSelect_getlay(result, data);
            //执行结果回调函数
            if ($("#resultcallback").val()) {
                eval("window.parent.${resultcallback}(result)");
            }
            //当你在iframe页面关闭自身时
            var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
            parent.layer.close(index); //再执行关闭
        }

    }
</script>
